package cn.gailvlun.gll.presentation.apartment;

import android.app.Dialog;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import cn.gailvlun.gll.R;
import cn.gailvlun.gll.bean.PlaceHolder;
import cn.gailvlun.gll.chatlib.event.MessageEvent;
import cn.gailvlun.gll.chatlib.message.Message;
import cn.gailvlun.gll.databinding.ActivityApartmentDetailBinding;
import cn.gailvlun.gll.net.HttpMethods;
import cn.gailvlun.gll.net.HttpSubscriber;
import cn.gailvlun.gll.net.Member;
import cn.gailvlun.gll.net.apartment.member.AddMemberReq;
import cn.gailvlun.gll.net.apartment.room.GetRoomDetailRes;
import cn.gailvlun.gll.net.apartment.room.Room;
import cn.gailvlun.gll.net.apartment.room.RoomStatus;
import cn.gailvlun.gll.net.apartment.room.SubscribeRoomReq;
import cn.gailvlun.gll.net.base.Profile;
import cn.gailvlun.gll.presentation.apartment.room.BeforeEnterRoomNoticeActivity;
import cn.gailvlun.gll.presentation.apartment.room.CreateRoomActivity;
import cn.gailvlun.gll.presentation.apartment.room.InviteFriendActivity;
import cn.gailvlun.gll.presentation.apartment.room.MatchActivity;
import cn.gailvlun.gll.presentation.apartment.room.MatchProfileActivity;
import cn.gailvlun.gll.presentation.apartment.room.MatchRuleActivity;
import cn.gailvlun.gll.presentation.apartment.room.MatchSuccessActivity;
import cn.gailvlun.gll.presentation.apartment.vm.ApartmentDetailViewModel;
import cn.gailvlun.gll.presentation.base.App;
import cn.gailvlun.gll.presentation.base.BaseActivity;
import cn.gailvlun.gll.presentation.chat.ChatActivity;
import cn.gailvlun.gll.presentation.profile.OtherProfileActivity;
import cn.gailvlun.gll.presentation.profile.ProfileActivity;
import cn.gailvlun.gll.presentation.xroom.adapter.NormalDialog;
import cn.gailvlun.gll.util.DateUtil;
import cn.gailvlun.gll.util.DialogUtil;
import cn.gailvlun.gll.util.ProfileUtil;
import cn.gailvlun.gll.util.RxUtil;
import cn.gailvlun.gll.util.SPUtil;
import cn.gailvlun.gll.util.ToastUtil;
import cn.gailvlun.gll.widget.NavigationBarView;
import cn.gailvlun.gll.widget.OnCancelListener;
import cn.gailvlun.gll.widget.OnConfirmListener;
import io.reactivex.functions.Consumer;


public class ApartmentDetailActivity extends BaseActivity {

    public static void openActivity(Context context) {
        Intent intent = new Intent(context, ApartmentDetailActivity.class);
        context.startActivity(intent);
    }

    public static void openActivity(Context context, int roomId) {
        Intent intent = new Intent(context, ApartmentDetailActivity.class);
        intent.putExtra("roomId", roomId);
        context.startActivity(intent);
    }

    public static void openFromNotification(Context context, int roomId) {
        Intent intent = new Intent(context, ApartmentDetailActivity.class);
        intent.putExtra("roomId", roomId);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void openActivity(Context context, int roomId, int inviterId) {
        Intent intent = new Intent(context, ApartmentDetailActivity.class);
        intent.putExtra("roomId", roomId);
        intent.putExtra("isInvited", true);
        intent.putExtra("inviterId", inviterId);
        context.startActivity(intent);
    }

    private int mRoomId;
    private static Boolean mIsInvited;
    private static Profile inviterProfile;

    private ActivityApartmentDetailBinding mBinding;

    @Override
    protected void initComponent() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_apartment_detail);
        mBinding.setPresenter(new Presenter());
    }

    @Override
    protected void createHandler() {
        mBinding.nbv.setOnBackListener(new NavigationBarView.OnBackListener() {
            @Override
            public void onBack(NavigationBarView nb) {
                onBackPressed();
            }
        });
        mBinding.nbv.setOnMenuClickListener(new NavigationBarView.OnMenuClickListener() {
            @Override
            public void onMenuClick(NavigationBarView nb) {
                ToastUtil.showShort("更多");
            }
        });
    }

    private ApartmentDetailViewModel mViewModel;

    @Override
    protected void loadData(@Nullable Bundle savedInstanceState) {
        mRoomId = getIntent().getIntExtra("roomId", -1);
        mIsInvited = getIntent().getBooleanExtra("isInvited", false);

        mViewModel = ViewModelProviders.of(this).get(ApartmentDetailViewModel.class);

        if (mRoomId == -1) {

            return;
        }
        if (mIsInvited) {
            int inviterId = getIntent().getIntExtra("inviterId", -1);
            if (inviterId != -1) {
                inviterProfile = mViewModel.getChatUser(inviterId);
            }
        }
    }

    @Override
    protected void onStart() {
        super.onStart();

        refreshApartmentDetail();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);


    }

    private void refreshApartmentDetail() {
        final Dialog progressDialog = DialogUtil.showIndeterminate(mContext);
        HttpMethods.getRoomService()
                .getRoomDetail(mRoomId)
                .compose(RxUtil.<GetRoomDetailRes>applyScheduler())
                .compose(this.<GetRoomDetailRes>bindToLifecycle())
                .subscribe(new HttpSubscriber<GetRoomDetailRes>() {
                    @Override
                    protected void onSuccess(GetRoomDetailRes response) {
                        mBinding.setItem(response);

                        mViewModel.saveRoom(response.getRoom());
                        mViewModel.saveMember(response.getMember());
                        progressDialog.dismiss();
                    }

                    @Override
                    protected void onFailure(String errMsg, @Nullable GetRoomDetailRes response, int code) {
                        progressDialog.dismiss();
                        DialogUtil.showError(mContext, errMsg);
                    }
                });
    }

    @Override
    protected void onDestroy() {
        mIsInvited = null;
        inviterProfile = null;
        super.onDestroy();
    }

    public class Presenter {
        public void getNotice(GetRoomDetailRes getRoomDetailRes) {
            final Dialog pd = DialogUtil.showIndeterminate(mContext);

            // 获取通知
            NormalDialog dialog = new NormalDialog(mContext, "是否开启报名提醒", "报名开始时，你将第一时间收到消息通知", "好的", "先不了");
            dialog.setOnCancelListener(new OnCancelListener<Object>() {
                @Override
                public void onCancel(@NotNull Dialog dialog, @org.jetbrains.annotations.Nullable Object data) {
                    dialog.dismiss();
                }
            });
            dialog.setOnConfirmListener(new OnConfirmListener<Object>() {
                @Override
                public void onConfirm(@NotNull Dialog dialog, @org.jetbrains.annotations.Nullable Object data) {
                    dialog.dismiss();
                    SubscribeRoomReq subscribeRoomReq = new SubscribeRoomReq();
                    subscribeRoomReq.setRoom_id(mRoomId);
                    HttpMethods.getRoomService()
                            .subscribeRoom(subscribeRoomReq)
                            .compose(RxUtil.<Room>applyScheduler())
                            .compose(ApartmentDetailActivity.this.<Room>bindToLifecycle())
                            .subscribe(new HttpSubscriber<Room>() {
                                @Override
                                protected void onSuccess(Room response) {
                                    refreshApartmentDetail();
                                }

                                @Override
                                protected void onFailure(String errMsg, @Nullable Room response, int code) {
                                    DialogUtil.showError(mContext, errMsg);
                                }

                                @Override
                                protected void onFinish() {
                                    super.onFinish();

                                    pd.dismiss();
                                }
                            });
                }
            });
            dialog.show();
        }

        public void enterProfile(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes.getMember().isIs_host()) {
                ProfileActivity.openActivity(mContext);
            } else {

                OtherProfileActivity.openActivity(mContext, getRoomDetailRes.getRoom().getOwner());
            }
        }

        public void clickBottomText(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return;
            }


            boolean isHost = getRoomDetailRes.getMember().isIs_host();
            boolean isSigned = getRoomDetailRes.getMember().isIs_apply();
            boolean isFull = getRoomDetailRes.getRoom().getMember_count() == getRoomDetailRes.getRoom().getMember_max();

            if (isHost) {
                switch (getRoomDetailRes.getRoom().getStatus()) {
                    case UN_REVIEW:
                        return;
                    case OPENING:
                        ChatActivity.openActivity(mContext, "room:" + getRoomDetailRes.getRoom().getId());
                        return;
                    case END:
                        return;
                    case REVIEW_PASS:

                        OpenSigningActivity.Companion.openActivity(mContext, getRoomDetailRes.getRoom().getId());
                        return;
                    case WAITING_FOR_SIGNING:
                        return;
                    case REVIEW_OBJECTION:

                        mViewModel.saveRoom(getRoomDetailRes.getRoom());
                        CreateRoomActivity.openActivity(mContext, getRoomDetailRes.getRoom().getId());
                        return;
                    case SIGNING:
                        return;
                    case SIGNING_COMPLETE:
                        return;
                }
            } else {
                switch (getRoomDetailRes.getRoom().getTag()) {
                    case J:
                    case B:
                    case X:
                    case T: {
                        if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return;
                                case END:
                                    return;
                                case SIGNING: {
                                    if (!isFull) {
                                        BeforeEnterRoomNoticeActivity.openActivity(mContext, getRoomDetailRes.getRoom());
                                        return;
                                    } else {
                                        return;
                                    }
                                }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    ChatActivity.openActivity(mContext, "room:" + getRoomDetailRes.getRoom().getId());
                                    return;
                                case END:
                                    return;
                                case SIGNING: {
                                    return;
                                }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        }
                        break;
                    }
                    case D: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_apply() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_apply() && getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    ChatActivity.openActivity(mContext, "room:" + getRoomDetailRes.getRoom().getId());
                                    return;
                                case END:
                                    return;
                                case SIGNING:

                                    MatchSuccessActivity.openActivity(mContext, getRoomDetailRes.getMember().getCoupleId());
                                    return;
                                case SIGNING_COMPLETE:

                                    MatchSuccessActivity.openActivity(mContext, getRoomDetailRes.getMember().getCoupleId());
                                    return;
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return;
                                case END:
                                    return;
                                case SIGNING:
                                    if (!isFull) {

                                        MatchActivity.openActivity(mContext, getRoomDetailRes.getMember().getId(), getRoomDetailRes.getRoom().getId());
                                        return;
                                    } else {
                                        return;
                                    }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        } else if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return;
                                case END:
                                    return;
                                case SIGNING:
                                    if (!isFull) {
                                        boolean singleRule = SPUtil.getBoolean(SPUtil.USER, "isSingleRuleRead");
                                        if (singleRule) {
                                            MatchProfileActivity.openActivity(mContext, mRoomId);
                                        } else {
                                            MatchRuleActivity.openActivity(mContext, mRoomId);
                                        }
                                        return;
                                    } else {
                                        return;
                                    }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        }
                        break;
                    }
                    case A:
                    case L:
                    case Y: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_agree() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    ChatActivity.openActivity(mContext, "room:" + getRoomDetailRes.getRoom().getId());
                                    return;
                                case END:
                                    return;
                                case SIGNING:

                                    MatchSuccessActivity.openActivity(mContext, getRoomDetailRes.getMember().getCoupleId());
                                    return;
                                case SIGNING_COMPLETE:

                                    MatchSuccessActivity.openActivity(mContext, getRoomDetailRes.getMember().getCoupleId());
                                    return;
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return;
                                case END:
                                    return;
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            acceptInvite(getRoomDetailRes.getRoom(), inviterProfile);
                                            return;
                                        } else {
                                            InviteFriendActivity.openActivity(mContext, getRoomDetailRes.getRoom());
                                            return;
                                        }
                                    } else {
                                        return;
                                    }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return;
                                case END:
                                    return;
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            acceptInvite(getRoomDetailRes.getRoom(), inviterProfile);
                                            return;
                                        } else {
                                            BeforeEnterRoomNoticeActivity.openActivity(mContext, getRoomDetailRes.getRoom(), true);
                                            return;
                                        }
                                    } else {
                                        return;
                                    }
                                case SIGNING_COMPLETE:
                                    return;
                            }
                        }
                    }
                }
            }
        }
    }

    private void acceptInvite(final Room theRoom, final Profile inviter) {

        AddMemberReq addMemberReq = new AddMemberReq(theRoom.getId());
        addMemberReq.setInviter_id(inviter.getId());
        HttpMethods.getMemberService()
                .addMember(addMemberReq)
                .compose(RxUtil.<Member>applyScheduler())
                .compose(this.<Member>bindToLifecycle())
                .subscribe(new HttpSubscriber<Member>() {
                    @Override
                    protected void onSuccess(Member response) {

                        mViewModel.saveProfile(inviter);
                        final Message msg = Message.text(getString(R.string.thanks_for_room_invite), new Date(), ProfileUtil.getProfile(), "user:" + inviter.getId());
                        mViewModel.save(msg);

                        RxUtil.timer(100, TimeUnit.MILLISECONDS)
                                .subscribe(new Consumer<Long>() {
                                    @Override
                                    public void accept(Long aLong) throws Exception {

                                        EventBus.getDefault().post(new MessageEvent(msg.getId(), msg.getDialogId()));
                                    }
                                });

                        refreshApartmentDetail();
                    }

                    @Override
                    protected void onFailure(String errMsg, @Nullable Member response, int code) {
                        DialogUtil.showError(mContext, errMsg);
                    }
                });
    }

    public static class Util {
        public static int getBottomTextVisibility(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) return View.VISIBLE;
            switch (getRoomDetailRes.getRoom().getStatus()) {
                case ABORT:
                case WAITING_FOR_SIGNING:
                    if (getRoomDetailRes.getMember().isIs_host()) {
                        return View.VISIBLE;
                    } else {
                        return View.GONE;
                    }
                default:
                    return View.VISIBLE;
            }
        }

        public static int getNotSignVisibility(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return View.GONE;
            }
            if (getRoomDetailRes.getMember().isIs_host()) {
                return View.GONE;
            }
            if (getRoomDetailRes.getRoom().getStatus() == RoomStatus.WAITING_FOR_SIGNING) {
                return View.VISIBLE;
            } else {
                return View.GONE;
            }
        }

        public static boolean isSignEnabled(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return false;
            }
            if (getRoomDetailRes.getRoom().isIs_sub()) {
                return false;
            }
            return true;
        }

        public static String getOpenTime(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return "";
            }
            if (!getRoomDetailRes.getRoom().getStatus().isPublished()) {
                return "预计开启时间";
            } else {
                return "房间开启时间";
            }
        }

        public static String getSignStartTime(GetRoomDetailRes getRoomDetailRes) {
            // TODO: 2018/9/17 ghy
            if (getRoomDetailRes == null) {
                return "";
            }
//            if (getRoomDetailRes.getRoom().getStatus().isDisplaySignDate()) {
            return DateUtil.format(DateUtil.NO_SECOND_PATTERN, getRoomDetailRes.getRoom().getApply_datetime());
//            } else {
//                return DateUtil.format(DateUtil.NO_SECOND_PATTERN, getRoomDetailRes.getRoom().getApply_datetime());
//            }
        }

        public static int getSignStartEnabled(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return View.GONE;
            }
            if (getRoomDetailRes.getRoom().getStatus().isDisplaySignDate()) {
                return View.VISIBLE;
            } else {
                return View.GONE;
            }
        }

        public static String getRoomDuration(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return null;
            }
            long startTime = getRoomDetailRes.getRoom().getStart_datetime().getTime();
            long endTime = getRoomDetailRes.getRoom().getClose_datetime().getTime();

            long hours = (endTime - startTime) / 1000 / 60 / 60;
            if (hours < 24) {
                return hours + "小时";
            }
            return hours / 24 + "天";
        }

        public static String getOpenDate(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return "";
            }
            if (!getRoomDetailRes.getRoom().getStatus().isPublished()) {

                return DateUtil.format(DateUtil.NO_SECOND_PATTERN, getRoomDetailRes.getRoom().getStart_datetime());
            } else {
                return DateUtil.format(DateUtil.NO_SECOND_PATTERN, getRoomDetailRes.getRoom().getStart_datetime());
            }
        }

        public static String getRoomImage(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return "";
            }
            return getRoomDetailRes.getRoom().getPic();
        }

        public static SpannableString getMemberStatus(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return null;
            }
            SpannableStringBuilder ssb = new SpannableStringBuilder();
            ssb.append(String.valueOf(getRoomDetailRes.getRoom().getMember_count()))
                    .append("人参与 . 剩余")
                    .append(String.valueOf(getRoomDetailRes.getRoom().getMember_max() - getRoomDetailRes.getRoom().getMember_count()))
                    .append("名额");
            int start = String.valueOf(getRoomDetailRes.getRoom().getMember_count()).length() + 8;
            int end = start + String.valueOf(getRoomDetailRes.getRoom().getMember_max() - getRoomDetailRes.getRoom().getMember_count()).length();
            ssb.setSpan(new ForegroundColorSpan(App.getInstance().getResources().getColor(R.color.apricot)),
                    start, end,
                    Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            return SpannableString.valueOf(ssb);
        }

        public static String getTag(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return "";
            }
            return App.getInstance().getString(getRoomDetailRes.getRoom().getTag().getTitle());
        }

        public static Drawable getBottomBG(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return null;
            }


            boolean isHost = getRoomDetailRes.getMember().isIs_host();
            boolean isSigned = getRoomDetailRes.getMember().isIs_apply();
            boolean isFull = getRoomDetailRes.getRoom().getMember_count() == getRoomDetailRes.getRoom().getMember_max();

            if (isHost) {
                switch (getRoomDetailRes.getRoom().getStatus()) {
                    case UN_REVIEW:
                    case OPENING:
                    case END:
                    case REVIEW_PASS:
                        return App.getInstance().getResources().getDrawable(R.drawable.no_radius_robin_segg_bg);
                    case REVIEW_OBJECTION:
                        return App.getInstance().getResources().getDrawable(R.drawable.no_radius_salmon_bg);
                    case SIGNING:
                    case SIGNING_COMPLETE:
                }
            } else {
                switch (getRoomDetailRes.getRoom().getTag()) {
                    case J:
                    case B:
                    case X:
                    case T: {
                        if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING: {
                                    if (!isFull) {
                                    } else {
                                    }
                                }
                                case SIGNING_COMPLETE:
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING: {
                                }
                                case SIGNING_COMPLETE:
                            }
                        }
                        break;
                    }
                    case D: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_apply() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_apply() && getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    return App.getInstance().getResources().getDrawable(R.drawable.no_radius_robin_segg_bg);
                                case SIGNING_COMPLETE:
                                    return App.getInstance().getResources().getDrawable(R.drawable.no_radius_robin_segg_bg);
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    if (!isFull) {
                                    } else {
                                    }
                                case SIGNING_COMPLETE:
                            }
                        } else if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    if (!isFull) {
                                    } else {
                                    }
                                case SIGNING_COMPLETE:
                            }
                        }
                        break;
                    }
                    case A:
                    case L:
                    case Y: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_agree() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    return App.getInstance().getResources().getDrawable(R.drawable.no_radius_robin_segg_bg);
                                case SIGNING_COMPLETE:
                                    return App.getInstance().getResources().getDrawable(R.drawable.no_radius_robin_segg_bg);
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                        } else {
                                        }
                                    } else {
                                    }
                                case SIGNING_COMPLETE:
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                case END:
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                        } else {
                                        }
                                    } else {
                                    }
                                case SIGNING_COMPLETE:
                            }
                        }
                    }
                }
            }
            return App.getInstance().getResources().getDrawable(R.drawable.no_radius_important_btn_bg);
        }

        public static String getSecondBottomText(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return null;
            }
            switch (getRoomDetailRes.getRoom().getStatus()) {
                case REVIEW_PASS:
                    return "若不操作，则房间开启时间会自动删除";
                case REVIEW_OBJECTION:
                    return "若不操作，则24小时后房间自动删除";
                default:
                    return null;
            }
        }

        public static int getSecondBottomTextVisibility(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return View.GONE;
            }
            switch (getRoomDetailRes.getRoom().getStatus()) {
                case REVIEW_PASS:
                case REVIEW_OBJECTION:
                    return View.VISIBLE;
                default:
                    return View.GONE;
            }
        }

        public static String getBottomText(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return null;
            }


            boolean isHost = getRoomDetailRes.getMember().isIs_host();
            boolean isSigned = getRoomDetailRes.getMember().isIs_apply();
            boolean isFull = getRoomDetailRes.getRoom().getMember_count() == getRoomDetailRes.getRoom().getMember_max();

            if (isHost) {
                switch (getRoomDetailRes.getRoom().getStatus()) {
                    case UN_REVIEW:
                        return "房间待审核";
                    case OPENING:
                        return "进入房间";
                    case END:
                        return "房间已结束";
                    case REVIEW_PASS:
                        return "确认上线";
                    case WAITING_FOR_SIGNING:
                        return "等待报名开始";
                    case REVIEW_OBJECTION:
                        return "修改房间";
                    case SIGNING:
                        return "报名中";
                    case SIGNING_COMPLETE:
                        return "等待房间开启";
                    case ABORT:
                        return "已取消";
                }
            } else {
                switch (getRoomDetailRes.getRoom().getTag()) {
                    case J:
                    case B:
                    case X:
                    case T: {
                        if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "报名结束";
                                case END:
                                    return "房间已结束";
                                case SIGNING: {
                                    if (!isFull) {
                                        return "报名";
                                    } else {
                                        return "报名结束";
                                    }
                                }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "进入房间";
                                case END:
                                    return "房间已结束";
                                case SIGNING: {
                                    return "等待房间开启";
                                }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        }
                        break;
                    }
                    case D: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_apply() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_apply() && getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "进入房间";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    return "查看我的CP";
                                case SIGNING_COMPLETE:
                                    return "查看我的CP";
                                case ABORT:
                                    return "已取消";
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "报名结束";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    if (!isFull) {
                                        return "匹配中";
                                    } else {
                                        return "报名结束";
                                    }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        } else if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "报名结束";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    if (!isFull) {
                                        return "报名";
                                    } else {
                                        return "报名结束";
                                    }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        }
                        break;
                    }
                    case A:
                    case L:
                    case Y: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_agree() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "进入房间";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    return "查看我的CP";
                                case SIGNING_COMPLETE:
                                    return "查看我的CP";
                                case ABORT:
                                    return "已取消";
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "报名结束";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            return "接受邀请";
                                        } else {
                                            return "继续邀请";
                                        }
                                    } else {
                                        return "报名结束";
                                    }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return "报名结束";
                                case END:
                                    return "房间已结束";
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            return "接受邀请";
                                        } else {
                                            return "邀请CP加入";
                                        }
                                    } else {
                                        return "报名结束";
                                    }
                                case SIGNING_COMPLETE:
                                    return "报名结束";
                                case ABORT:
                                    return "已取消";
                            }
                        }
                    }
                }
            }
            return null;
        }

        public static boolean getBottomTextEnabled(GetRoomDetailRes getRoomDetailRes) {
            if (getRoomDetailRes == null) {
                return false;
            }


            boolean isHost = getRoomDetailRes.getMember().isIs_host();
            boolean isSigned = getRoomDetailRes.getMember().isIs_apply();
            boolean isFull = getRoomDetailRes.getRoom().getMember_count() == getRoomDetailRes.getRoom().getMember_max();

            if (isHost) {
                switch (getRoomDetailRes.getRoom().getStatus()) {
                    case UN_REVIEW:
                        return false;
                    case OPENING:
                        return true;
                    case END:
                        return false;
                    case REVIEW_PASS:
                        return true;
                    case WAITING_FOR_SIGNING:
                        return false;
                    case REVIEW_OBJECTION:
                        return true;
                    case SIGNING:
                        return false;
                    case SIGNING_COMPLETE:
                        return false;
                }
            } else {
                switch (getRoomDetailRes.getRoom().getTag()) {
                    case J:
                    case B:
                    case X:
                    case T: {
                        if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return false;
                                case END:
                                    return false;
                                case SIGNING: {
                                    if (!isFull) {
                                        return true;
                                    } else {
                                        return false;
                                    }
                                }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return true;
                                case END:
                                    return false;
                                case SIGNING: {
                                    return false;
                                }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        }
                        break;
                    }
                    case D: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_apply() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_apply() && getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return true;
                                case END:
                                    return false;
                                case SIGNING:
                                    return true;
                                case SIGNING_COMPLETE:
                                    return true;
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return false;
                                case END:
                                    return false;
                                case SIGNING:
                                    if (!isFull) {
                                        return true;
                                    } else {
                                        return false;
                                    }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        } else if (!isSigned) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return false;
                                case END:
                                    return false;
                                case SIGNING:
                                    if (!isFull) {
                                        return true;
                                    } else {
                                        return false;
                                    }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        }
                        break;
                    }
                    case A:
                    case L:
                    case Y: {
                        boolean isMatching = getRoomDetailRes.getMember().isIs_agree() && !getRoomDetailRes.getMember().isIs_match();
                        boolean isMatched = getRoomDetailRes.getMember().isIs_match();
                        if (isMatched) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return true;
                                case END:
                                    return false;
                                case SIGNING:
                                    return true;
                                case SIGNING_COMPLETE:
                                    return true;
                            }
                        } else if (isMatching) {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return false;
                                case END:
                                    return false;
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            return true;
                                        } else {
                                            return true;
                                        }
                                    } else {
                                        return false;
                                    }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        } else {
                            switch (getRoomDetailRes.getRoom().getStatus()) {
                                case OPENING:
                                    return false;
                                case END:
                                    return false;
                                case SIGNING:
                                    if (!isFull) {
                                        if (mIsInvited && inviterProfile.getId() != ProfileUtil.getUserId()) {
                                            return true;
                                        } else {
                                            return true;
                                        }
                                    } else {
                                        return false;
                                    }
                                case SIGNING_COMPLETE:
                                    return false;
                            }
                        }
                    }
                }
            }
            return false;
        }
    }
}
